<extend file='resource/view/master'/>
<block name="content">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">

                <if condition="$is_show">
                    <form action="{:U('add')}" method='post'>
                </if>
                <table class='table table-bordered table-hover'>
                    <tr>
                        <th>货品ID</th>

                        <foreach name='spec' item='v'>
                            <th>{$v.taname}</th>
                        </foreach>

                        <th>库存</th>
                        <th>货号</th>
                        <th>操作</th>
                    </tr>

                    <foreach name='list' item='v'>
                        <tr class="info">
                            <td>{$v.glid}</td>
                            <foreach name='v.spec' item='s'>
                                <td>{$s}</td>
                            </foreach>
                            <td>{$v.inventory}</td>
                            <td>{$v.number}</td>
                            <td>
                                <a href="{:U('edit', array('glid' => $v['glid']))}" class="btn btn-warning"><i class="icon-pencil icon-white"></i>修改</a>
                                <a href="{:U('del', array('glid' => $v['glid']))}" class="btn btn-danger"><i class="icon-trash icon-white"></i>删除</a>
                            </td>
                        </tr>
                    </foreach>

                    <!-- 如果已添加数目小于可能情况数目，才出现添加货品的输入框 -->
                    <if condition="$is_show">
                        <tr class="info">
                            <td>添加货品</td>

                            <foreach name='spec' item='v'>
                                <td>
                                    <select name="spec[]">
                                        <option value="0">-请选择-</option>
                                        <foreach name='v.opt' item='s'>
                                            <option value="{$s.gtid}">{$s.gtvalue}</option>
                                        </foreach>
                                    </select>
                                </td>
                            </foreach>


                            <td>
                                <input type="text" name='inventory'/>
                            </td>
                            <td>
                                <input type="text" name='number' value="" />
                            </td>
                            <td></td>
                        </tr>
                    </if>
                </table>

                <if condition="$is_show">
                    <input type="hidden" name='gid' value='{$Think.get.gid}'/>
                    <input type="hidden" name='tid' value='{$Think.get.tid}'/>
                    <input type="submit" value='保存添加' class="btn btn-primary"/>
                    </form>
                </if>

            </div>
        </div>
    </div>
</block>
<script>
    function add()
    {
        var data = $('#form').serialize();
        //res返回的数据：{valid:0,message:'提示信息'}
        $.post("{{u('add')}}",data,function(res){
            if(res.valid)
            {//成功
                //参数：提示消息，跳转地址，成功/失败
                util.message(res.message,"{{u('index')}}",'success');
            }else{
                util.message(res.message,"",'error');
            }
        },"json")
        return false;
    }
</script>
